﻿@using OShop.Extensions
@using OShop.Models
@using Orchard.ContentManagement
@using Orchard.Core.Contents.ViewModels;
@{
    Style.Require("OShopAdmin");

    var pageTitle = T("Manage Products");
    var createLinkText = T("Create New Product");

    if (!string.IsNullOrWhiteSpace(Model.TypeDisplayName)) {
        pageTitle = T("Manage {0} products", Model.TypeDisplayName);
        createLinkText = T("Create New {0}", Model.TypeDisplayName);
    }
        
    Layout.Title = pageTitle;
}

<div class="manage">
    @if (!string.IsNullOrWhiteSpace(Model.TypeDisplayName)) {
        @Html.ActionLink(createLinkText.Text, "Create", "Admin", new { Area = "Contents", Id = (string)Model.Options.SelectedFilter }, new { @class = "button primaryAction" })
    }
    else {
        @Html.ActionLink(createLinkText.Text, "Create", "ProductsAdmin", new { Area = "OShop", Id = (string)Model.Options.SelectedFilter }, new { @class = "button primaryAction" })
    }
</div>
@using (Html.BeginFormAntiForgeryPost(Url.Action("Index", "ProductsAdmin", new { area = "OShop", returnUrl = Context.Request.RawUrl }))) {
    <fieldset class="bulk-actions">
        <label for="publishActions">@T("Actions:")</label>
        <select id="publishActions" name="Options.BulkAction">
            @Html.SelectOption((ContentsBulkAction)Model.Options.BulkAction, ContentsBulkAction.None, T("Choose action...").ToString())
            @Html.SelectOption((ContentsBulkAction)Model.Options.BulkAction, ContentsBulkAction.PublishNow, T("Publish Now").ToString())
            @Html.SelectOption((ContentsBulkAction)Model.Options.BulkAction, ContentsBulkAction.Unpublish, T("Unpublish").ToString())
            @Html.SelectOption((ContentsBulkAction)Model.Options.BulkAction, ContentsBulkAction.Remove, T("Delete").ToString())
        </select>
        <button type="submit" name="submit.BulkEdit" value="yes">@T("Apply")</button>
    </fieldset>
    <fieldset class="bulk-actions">
        <label for="filterResults" class="bulk-filter">@T("Show")</label>
        <select id="filterResults" name="Options.SelectedFilter">
            @Html.SelectOption((string)Model.Options.SelectedFilter, "", T("any (show all)").ToString())
            @foreach (var filterOption in Model.Options.FilterOptions) {
                @Html.SelectOption((string)Model.Options.SelectedFilter, (string)filterOption.Key, (string)filterOption.Value)
            }
        </select>
        <label for="orderResults" class="bulk-order">@T("Ordered by")</label>
        <select id="orderResults" name="Options.OrderBy">
            @Html.SelectOption((ContentsOrder)Model.Options.OrderBy, ContentsOrder.Created, T("recently created").ToString())
            @Html.SelectOption((ContentsOrder)Model.Options.OrderBy, ContentsOrder.Modified, T("recently modified").ToString())
            @Html.SelectOption((ContentsOrder)Model.Options.OrderBy, ContentsOrder.Published, T("recently published").ToString())
        </select>
        <label for="contentResults" class="bulk-order">@T("Filter by")</label>
        <select id="contentResults" name="Options.ContentsStatus">
            @Html.SelectOption((ContentsStatus)Model.Options.ContentsStatus, ContentsStatus.Latest, T("latest").ToString())
            @Html.SelectOption((ContentsStatus)Model.Options.ContentsStatus, ContentsStatus.Published, T("published").ToString())
            @Html.SelectOption((ContentsStatus)Model.Options.ContentsStatus, ContentsStatus.Draft, T("unpublished").ToString())
            @Html.SelectOption((ContentsStatus)Model.Options.ContentsStatus, ContentsStatus.AllVersions, T("all versions").ToString())
        </select>
        <button type="submit" name="submit.Filter" value="yes please">@T("Apply")</button>
    </fieldset>
    <fieldset class="contentItems bulk-items">
        @Display(Model.ContentItems)
    </fieldset>
    @Display(Model.Pager)
}